//
// Created by Martin on 2021/9/30.
//

#include "Waiter.h"
#include <typeinfo>
#include <iostream>

using namespace std;

void Waiter::setOrder(Command *command)
{
    if (!command) return;

    orders.push_back(command);

    // 获取当前本地时间
    struct tm *res_time;
    time_t now_time = time(nullptr);
    size_t n = 0;
    char buf[512];

    // convert time_t => tm (local time)
    res_time = localtime(&now_time);
    // 格式化日期、时间输出格式：年-月-日 时:分:秒
    n = strftime(buf, sizeof(buf), "%F %T", res_time);

    cout << "增加订单：" << command->getFoodName() << " 时间：" << buf << endl;
}

void Waiter::cancelOrder(Command *command)
{
    for (auto it = orders.begin(); it != orders.end(); ) {
        if (*it == command) {
            orders.erase(it++);
        } else {
            it++;
        }
    }
}

void Waiter::notify()
{
    for (auto e : orders) {
        e->executeCommand();
    }
}

Waiter::Waiter()
{
}

Waiter::~Waiter()
{

}
